package cn.agiledata.bank.linkbank.impl.abc;

import java.math.BigDecimal;
import java.util.Date;

import com.hitrust.trustpay.client.TrxResponse;
import cn.agiledata.bank.common.util.DateUtil;

/**
 * 中国农业银行网上银行订单构建器
 * 
 * @author 马贤波
 * 
 */
public final class AbcOrderBuilder {
    AbcOrder build(TrxResponse trxResponse) {
        if (!trxResponse.isSuccess())
            return null;
        AbcOrder order = new AbcOrder();
        String orderAmount = trxResponse.getValue("OrderAmount");
        order.setAmount(new BigDecimal(orderAmount));
        String dateValue = trxResponse.getValue("OrderDate");
        String timeValue = trxResponse.getValue("OrderTime");
        Date createTime = DateUtil.string2Date(dateValue + " " + timeValue,
                AbcNetConstant.DATE_FORMAT + " "
                        + AbcNetConstant.TIME_FORMAT);
        order.setCreateTime(createTime);
        order.setOrderId(trxResponse.getValue("OrderNo"));
        order.setRemark(trxResponse.getValue("OrderDesc"));
        order.setStatus(trxResponse.getValue("OrderStatus"));
        return order;
    }

    AbcOrder build(String s) {
        AbcOrder order = new AbcOrder();
        String[] values = s.split(",");
        boolean paymentOrder = "P".equals(values[0]);
        order.setPaymentOrder(paymentOrder);
        String orderId = values[1];
        order.setOrderId(orderId);
        BigDecimal amount = new BigDecimal(values[2]);
        order.setAmount(amount);
        String voucherNo = values[3];
        order.setVoucherNo(voucherNo);
        Date createTime = DateUtil.string2Date(values[4],
                AbcNetConstant.DATE_TIME_FORMAT);
        order.setCreateTime(createTime);
        return order;
    }
}
